package com.yanqu.road.server.cmd.activity.qixi.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.QixiProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.qixi.QixiModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;

@Cmd(code = GameProtocol.S_QIXI_FLOWER_BROADCAST, desc = "七夕送花广播跨服返回")
public class QixiBroadcastCrossBackCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        QixiProto.CrossQixiBroadcastBackMsg resultMsg = QixiProto.CrossQixiBroadcastBackMsg.parseFrom(packet.getBytes());
        if (resultMsg.getTargetUserId() == 0) {
            //全部广播
            List<GamePlayer> allOnlinePlayer = GamePlayerMgr.getAllOnlinePlayer();
            for (GamePlayer gamePlayer : allOnlinePlayer) {
                gamePlayer.getModule(QixiModule.class).broadcastCrossBack(resultMsg);
            }
        } else {
            player.getModule(QixiModule.class).broadcastCrossBack(resultMsg);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
